package BlogHashBuck;

import java.util.*;

public class BlogTestMapSet {

    public static void main(String[] args) {
        Set<String> set=new TreeSet<String>();
        //add
        set.add("6张三");
        set.add("6张三");//重复元素虽有警告但无报错,且最后不会成功添加
        set.add("3李四");
        set.add("2王五");
        set.add("8赵六");
        set.add("4刘八");
        //Iterator
        System.out.println("========Iterator()=======");
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        //contains
        System.out.println("========contains()=======");
        System.out.println(set.contains("6张三"));
        System.out.println(set.contains("7陆七"));
        //remove()
        System.out.println("========remove()=======");
        System.out.println(set.remove("4刘八"));
        System.out.println(set.remove("7陆七"));//没有该元素,删除失败
        //size()
        System.out.println("========size()=======");
        System.out.println(set.size());
        //toArray()
        System.out.println("========toArray()=======");
        Object[] array=set.toArray();
        System.out.println(Arrays.toString(array));
        //containsAll(Collection<?> c)
        System.out.println("========containsAll(Collection<?> c)=======");
        Collection<String> c=new ArrayList<>();
        c.add("6张三");
        c.add("3李四");
        System.out.println(set.containsAll(c));
        //addAll(Collection<? extends E> c)
        System.out.println("========addAll(Collection<? extends E> c)=======");
        c.add("6张三");
        c.add("3李四");
        System.out.println(c);
        set.addAll(c);
        System.out.println(set);//set将collection中的元素全部去重并添加
        //isEmpty()
        System.out.println(set.isEmpty());
        //clear()
        set.clear();
        System.out.println(set.isEmpty());
    }


    public static void main1(String[] args) {
        Map<String,String> map=new TreeMap<>();//底层是二叉搜索树
        //put
        map.put("1熹贵妃","嬛嬛");
        map.put("9华妃","年世兰");
        map.put("3十七爷","果子狸");
        map.put("5惠妃","沈眉庄");
        map.put("7鹂妃","安陵容");
        map.put("4宁贵人","拽妃");
        map.put("8祺嫔","瓜六");
        //get
        System.out.println("=======get()======");
        String val1=map.get("1熹贵妃");
        System.out.println(val1);
        String val2=map.get("6胖橘");
        System.out.println(val2);//map中没有该值,返回null
        //getOrDefault
        System.out.println("=======getOrDefault()======");
        String val3=map.getOrDefault("2皇后","甄嬛传人物之一");
        System.out.println(val3);//没有找到该key,默认返回"甄嬛传人物之一"
        //remove
        System.out.println("=======remove()======");
        String val4=map.remove("9华妃");//华妃下线
        System.out.println(val4);//返回值是被删键值对的值
        //Map,Entry<K,V>
        System.out.println("=======Map,Entry<K,V>======");
        Set<Map.Entry<String,String>> entries=map.entrySet();
        System.out.println(entries);
        //getKey(),getValue(),setValue()
        System.out.println("=======getKey(),getValue(),setValue()======");
        for(Map.Entry<String,String> entry:entries){
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
            System.out.println(entry.setValue("1111"));//返回值是键值对修改之前的旧值
        }
        //keySet()
        System.out.println("=======keySet()======");
        Set<String> keySet=map.keySet();
        System.out.println(keySet);
        //values()
        System.out.println("=======values()======");
        Collection<String> values=map.values();
        System.out.println(values);
        //containsKey()
        System.out.println("=======containsKey()======");
        System.out.println(map.containsKey("8祺嫔"));
        //containsValue
        System.out.println("=======containsValue()======");
        System.out.println(map.containsKey("瓜六"));
    }
}
